package com.buka.server.service.Impl;


import com.buka.server.feign.UserFeign;
import com.buka.server.mapper.UserMapper;
import com.buka.server.pojo.SysUser;
import com.buka.server.pojo.UserControl;
import com.buka.server.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserFeign userFeign;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserControl userControl = new UserControl();
        userControl.setUsername(username);
        UserControl data = userFeign.findList(userControl).getData().get(0);
        SysUser sysUser = new SysUser();
        sysUser.setUsername(username);
        sysUser.setPassword(data.getPassword());
        sysUser.setStatus(data.getStatus());
        sysUser.setId(data.getId());
        sysUser.setRoles(data.getRole());
//        userMapper.findByUsername(username);
        return sysUser;
    }
}
